package com.mymoney;

import java.util.ArrayList;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.Toast;

public class BaseActivity extends Activity{

	protected static boolean finishActivity;
    private ProgressDialog activityDialog;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        finishActivity = false;
        
    }
    
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        boolean handle = super.onKeyDown(keyCode, event);

        // Eat the long press event so the keyboard doesn't come up.
        if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
            handle = true;
        }
        
        return handle;
    }
    
   
    public void showLoadingDialog(String text)
	{
        activityDialog = new ProgressDialog(this);
        activityDialog.setCancelable(false);
        setLoadingDialogText(text);
        activityDialog.show();
	}
	
	public void hideLoadingDialog()
	{
		if(activityDialog != null)
		{
			activityDialog.dismiss();
		}
	}
	
	public void setLoadingDialogText(String text)
	{
		if(activityDialog == null)
		{
			showLoadingDialog(text);
		}
		else
		{
			activityDialog.setMessage(text);
		}
	}
	
	public void showToast(String text)
	{
		int duration = Toast.LENGTH_SHORT;
		Toast toast = Toast.makeText(this, text, duration);
		toast.show();
	}
	
	public void showToasts(ArrayList<String> messages)
	{
		for(String message:messages)
		{
			int duration = Toast.LENGTH_SHORT;
			Toast toast = Toast.makeText(this, message, duration);
			toast.show();
			try {
				Thread.sleep(duration + 1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
